/* 成片管理，文件夹修改——最新接口 */
import request from '@/utils/request';
import {object2Url} from "@/utils/trans";

// 查询‘成片管理’文件夹
export async function selectPage2(username) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    username:username,
    ts,
    ua,
  };
  let url = `/business/finishProductFolder/selectPage${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

export async function selectPage (data) {
  const res = await request.post('/business/finishProductFolder/selectPage', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}



// 添加‘成片管理’文件夹
/*传参
* username:用户名
* type:2 (文件夹类型1:剪辑生成 2: 手动创建)
* name:文件来名称*/
export async function addSelectPage (data) {
  const res = await request.post('/business/finishProductFolder/save', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 导出文件夹——返回excel文件内容
export async function exportTemplate() {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
  };
  let url = `/business/montage/projectjob/exportTemplate${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 导出文件——返回下载路径，报错500暂不可用
export async function exportTemplateCeshi() {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
  };
  let url = `/business/montage/projectjob/ceshi${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}




// 删除成片文件夹
export async function delProjectjob (data) {
  const res = await request.post('/business/finishProductFolder/delete', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 查询成片文件夹下的视频
/*传参 仅： productPolderId:文件夹id*/
export async function queryVideos (data) {
  const res = await request.post('/business/montage/projectjob/page', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 将成片文件夹下的视频，全部或局部移动到另一个文件夹
/*
* 传值：
* productPolderId:文件夹id
* 参数 numberOfClips剪辑数 copyProductPolderId移入文件夹id  productPolderId复制文件夹id
* 移动文件夹id和移动类型（全部，部分）
* */
/*
export async function queryVideos3 (data) {
  const res = await request.post('/business/montage/projectjob/update', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}
*/


// 删除文件夹下的视频
export async function delVideoInfo (data) {
  const res = await request.post('/business/montage/projectjob/delete', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 查询文件夹下的视频
export async function queryVideoList(username) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
  };
  let url = `/business/montage/projectjob/page${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 将成片文件夹下的视频，全部或局部移动到另一个文件夹
// 复制文件夹移动——视频搬家
export async function updateVideoInfo (data) {
  const res = await request.post('/business/montage/projectjob/update', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}




